package dz.chuxin.framework.widget.rowview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import dz.chuxin.framework.R;

/**
 * RowView基类
 * Created by chuxin on 2016/7/17.
 */
public abstract class BaseRowView extends LinearLayout {

    public BaseRowView(Context context) {
        this(context, null);
    }

    public BaseRowView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BaseRowView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initializeView(context);
    }

    private void initializeView(Context context) {
        LayoutInflater.from(context).inflate(getRowLayoutResource(), this, true);
        setGravity(Gravity.CENTER_VERTICAL);
        setBackgroundResource(R.drawable.item_pressed_selector);
        initialize();
    }

    protected abstract void initialize();

    protected abstract int getRowLayoutResource();

    protected void stuffData(final BaseRowDescriptor rowDescriptor, final OnRowClickListener listener) {
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (rowDescriptor.isClickEnable && listener != null) listener.onRowClick(rowDescriptor);
            }
        });
    }
}
